package com.major.crowd.controller;

import com.major.crowd.api.MysqlRemoteService;
import com.major.crowd.constant.CrowdConstant;
import com.major.crowd.util.ResultEntity;
import com.major.crowd.vo.PortalTypeVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
public class PortalController {

    @Autowired
    private MysqlRemoteService mysqlRemoteService;

    /**
     * 首页
     * @return 首页
     */
    @RequestMapping("/")
    public String showPortalPage(Model model){

        // 调用方法，查到数据
        ResultEntity<List<PortalTypeVO>> resultEntity = mysqlRemoteService.getPortalTypeProjectDataRemote();

        // 判断查询成功
        String result = resultEntity.getResult();
        if (ResultEntity.SUCCESS.equals(result)){
            List<PortalTypeVO> data = resultEntity.getData();

            // 存入模型，返回给页面
            model.addAttribute(CrowdConstant.ATTR_NAME_PORTAL_DATA,data);
        }
        return "portal";
    }
}
